package demo1;

public class TestOne {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student("张三",18);
        Student student2 = (Student)student1.clone();
        System.out.println(student1);
        System.out.println(student2);
    }
}
//创建一个Student类
class Student implements Cloneable {
    //创建成员变量和构造方法
    public String name;
    public int age;
    public Student (String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "demo1.Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}